class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int slen = s.size(), plen = p.size();

        if (slen < plen) 
        {
            return vector<int>();
        }
        vector<int> ans;
        vector<int> sCount(26);
        vector<int> pCount(26);
        for(int i=0;i<plen;i++)//制造滑动窗口
        {
            sCount[s[i]-'a']++;
            pCount[p[i]-'a']++;
        }
        if(sCount==pCount)
            ans.emplace_back(0);
        for(int i=0;i<slen-plen;i++)
        {
            sCount[s[i]-'a']--;
            sCount[s[i+plen]-'a']++;
            if(sCount==pCount)
                ans.emplace_back(i+1);
        }
        return ans;
    }
};